package com.ruoyi.project.hcy.administrations.service.Impl;

import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.hcy.administrations.domain.Approve;
import com.ruoyi.project.hcy.administrations.domain.Train;
import com.ruoyi.project.hcy.administrations.mapper.ApproveMapper;
import com.ruoyi.project.hcy.administrations.mapper.TrainMapper;
import com.ruoyi.project.hcy.administrations.service.ITrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName TrainServiceImpl
 * @Author 金刚芭比
 * @Date 2020/9/17 10:54
 * @Version 1.0
 */
@Service
public class TrainServiceImpl implements ITrainService {

    @Autowired
    private TrainMapper trainMapper;

    @Autowired
    private ApproveMapper approveMapper;

    @Override
    public List<Train> selectTrainAll(String trainStatus) {
        return trainMapper.selectTrainAll(trainStatus);
    }

    @Override
    public int insertTrain(Train train) {
        //设置默认值
        train.setTrainType("培训申请");
        train.setTrainStatus("待审批..");
        int insert = trainMapper.insertTrain(train);
        if (insert>0){
            Approve approve = new Approve();
            approve.setApproveName(train.getTrainName());
            approve.setApproveStatus(train.getTrainStatus());
            approve.setApproveTitle(train.getTrainName()+"申请培训"+train.getTrainSkill()+",培训时长"+train.getTrainStage()+"个月");
            approve.setApproveType(train.getTrainType());
            approveMapper.insertApprove(approve);
        }
        return insert;
    }

    @Override
    public int updateTrainStatus(Train train) {
        return trainMapper.updateTrainStatus(train);
    }
}
